/**
 * 
 */
package com.ideal.trsdata.dao.ibatis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.transaction.annotation.Transactional;

import com.ideal.framework.pagetag.dao.impl.EntityDaoImpl;
import com.ideal.trsdata.dao.ITrsDataDao;
import com.ideal.trsdata.model.BusiModel;
import com.ideal.trsdata.model.DeptModel;
import com.ideal.trsdata.model.GpsInfoModel;
import com.ideal.trsdata.model.PeriodModel;
import com.ideal.trsdata.model.ProductModel;
import com.ideal.trsdata.model.TrsDataWarn;
import com.ideal.trsdata.model.TrsModel;


/**
 * @作者 杨鹏
 * @创建日期 May 22, 2009
 */
public class TrsDataDaoImpl extends  EntityDaoImpl implements ITrsDataDao{

	//得到宽表
	public List<TrsModel> getTmp(Map map) throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getTmp",map);
	}
	//得到宽表:单挑记录
	public TrsModel getSigTmp()throws Exception{
		return (TrsModel)this.getSqlMapClientTemplate().queryForObject("getSigTmp");
	}
	
	public List<TrsModel> getTmp2() throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getTmp2");
	}
	
	//得到客户信息
	public TrsModel getCustomer(TrsModel trs) throws Exception{
		return (TrsModel)this.getSqlMapClientTemplate().queryForObject("getOrg",trs);
	}

	//根据客户信息得到合同信息
	public List<Integer> getCONTRACT(TrsModel trs)throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getCONTRACT",trs);
	}

	//根据合同信息得到商品信息
	public List<Integer> getOFFERINGId(TrsModel trs) throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getOFFERING",trs);
	}

	//更具商品信息得到产品信息
	public List<Integer> getPRODUCT(Integer id) throws Exception{
	return this.getSqlMapClientTemplate().queryForList("getProduct",id);
	}

	//根据产品信息得到优先
	public TrsModel getrecommend(String id)throws Exception {
		return (TrsModel)this.getSqlMapClientTemplate().queryForObject("");
	}

	//得到政企等级
	public String getGrade(TrsModel trs) throws Exception{
		Integer i=(Integer)this.getSqlMapClientTemplate().queryForObject("getGrade",trs);
		return String.valueOf(i);
	}

	
	public ProductModel getProductSpeceId(Integer id)throws Exception {
		return (ProductModel)this.getSqlMapClientTemplate().queryForObject("getProductSpace",id);
	}

	
	//看政企是否有下级
	public String getDownGrade(TrsModel trs) throws Exception{
		return (String)this.getSqlMapClientTemplate().queryForObject("getdownGrade",trs);
	
	}
	
	//得到政企名称
	public String getRegionName(String regionCode)throws Exception{
		String regionName=(String)this.getSqlMapClientTemplate().queryForObject("getRegionName",regionCode);
		if(regionName==null)
			return "";
		return regionName;
		
	}


	public void insertTrs(TrsModel trs) throws Exception {
		this.getSqlMapClientTemplate().insert("insertTrs",trs);
	}

	public String getDesc(TrsModel trs) throws Exception {
		String desc1=(String)this.getSqlMapClientTemplate().queryForObject("getDocDesc",trs);
		String desc2=(String)this.getSqlMapClientTemplate().queryForObject("getDoc",trs);
		if(desc1==null)
			return desc2;
		if(desc2==null)
			return desc1;
		
		return desc1+desc2;
	}


	public ProductModel getRecommend(String code) throws Exception {
		return  (ProductModel)this.getSqlMapClientTemplate().queryForObject("getRecommend",code);
	}


	public List<String> getIndustryId(TrsModel trs) throws Exception {
		String key=(String)this.getSqlMapClientTemplate().queryForObject("getKeywordIdx",trs);
		return this.getSqlMapClientTemplate().queryForList("getKeywordValue",key);
	}
	
	public List<String> getSt(String key)throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getKeywordValue",key);
	}


	public List<String> getPropertyValue(TrsModel trs) throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getProperty",trs);
	}


	public void insertWarn(TrsDataWarn warn) throws Exception {
		this.getSqlMapClientTemplate().insert("insertWarn",warn);
	}


	public void updateTmpTrs(TrsModel trs) throws Exception {
		this.getSqlMapClientTemplate().update("updateTmp",trs);
	}
	
	public void updateTmpTrsFlag(Map map) throws Exception {
		this.getSqlMapClientTemplate().update("updateTmpFlag",map);
	}
	
	public void updateTmpTrsErr(Map map)throws Exception {
		this.getSqlMapClientTemplate().update("updateTmpTrsErr",map);
	}
	
	public 	void updateSigTmpFlag(Integer trsId)throws Exception {
		this.getSqlMapClientTemplate().update("updateSigTmpFlag", trsId);
	}

	public void deleteTrs(TrsModel trs) throws Exception {
		this.getSqlMapClientTemplate().delete("delTrs",trs);
	}

	
	public void insertFlow(TrsModel trs) throws Exception {
		this.getSqlMapClientTemplate().insert("insertFlow",trs);
	}


	public List<String> getManyProperty(TrsModel trs) throws Exception {
		return this.getSqlMapClientTemplate().queryForList("");
	}

	public String getPropertyValue(Map map) throws Exception {
		
		return (String)this.getSqlMapClientTemplate().queryForObject("findPropertyValue",map);
	}
	
	public List<ProductModel> getProperyList(Map map)throws Exception{
			return this.getSqlMapClientTemplate().queryForList("findListPorperty",map);
	}

	
	public List<ProductModel> getCustomerProduct(TrsModel trs) throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getCustomer-product",trs);
	}
	
	public List<String> getRe(String key)throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getRegionN",key);
	}
	
	

	public TrsModel getCus(Integer i) throws Exception {
		return (TrsModel)this.getSqlMapClientTemplate().queryForObject("getCus",i);
	}
	
	//每次得到多个客户
	public List<TrsModel>getListCus(Map map)throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getListCus",map);
	}
	
	public String getParentId(TrsModel trs)throws Exception{
		return (String)this.getSqlMapClientTemplate().queryForObject("getParentId",trs);
	}

	
	//判断是否为保密电话
	public String getPhoneType(TrsModel trs)throws Exception{
		return (String)this.getSqlMapClientTemplate().queryForObject("getTelSerct",trs);
	}
	
	//地址编码
	public String getCusCode(TrsModel trs) throws Exception {
		List l=this.queryList("getAddressCode",trs);
		if(l!=null&&l.size()>0)
			return (String)l.get(0);
		return null;
	}
	
	
	
	//得到部门
	public List<DeptModel> getDept(TrsModel trs)throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getDept",trs);
	}
	
	//部门电话处理
	public List<DeptModel> getDeptTel(DeptModel d)throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getDeptTel",d);
	}
	
	
	
	//部门总数
	public List<DeptModel> getDept_Tel(TrsModel trs)throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getDept_Tel",trs);
	}
	
	public Integer getDeptCount(TrsModel trs)throws Exception{
		return (Integer)this.getSqlMapClientTemplate().queryForObject("getDeptCount",trs);
	}
	
	//部门地址处理
	public String getDeptAddredd(DeptModel d)throws Exception{
		return (String)this.getSqlMapClientTemplate().queryForObject("getDeptAddress",d);
	}
	
	
	//得到政企电话
	public List<TrsModel> getTel(TrsModel cus) throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getOrgTel",cus);
	}
	
	/**
	 * 三统一增加集团业务( 张智 2010-09-20)
	 */
	//查询政企集团业务
	public List<String> getOrgBusinessInfos(TrsModel cus)throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getOrgBusinessInfos",cus);
	}
	
	//查询百事通加盟有效期
	public List<PeriodModel> getOrgBstjmValid(TrsModel cus)throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getOrgBstjmValid",cus);
	}
	
	//更新集团业务
	public void updateOrgBusiness(TrsModel trs)throws Exception{
		this.getSqlMapClientTemplate().update("updateOrgBusiness",trs);
	}
	
	//查询集团业务(订餐)
	public Integer getFoodBusinessInfo(TrsModel cus)throws Exception {
		Integer cnt = (Integer)this.getSqlMapClientTemplate().queryForObject("getFoodBusinessInfo",cus);
		if(cnt!=null && cnt>0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	//查询集团业务(订房)
	public Integer getHouseBusinessInfo(TrsModel cus)throws Exception {
		Integer cnt = (Integer)this.getSqlMapClientTemplate().queryForObject("getHouseBusinessInfo",cus);
		if(cnt!=null && cnt>0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	//查询集团业务(百事通加盟)
	public Integer getBstBusinessInfo(TrsModel cus)throws Exception {
		Integer cnt = (Integer)this.getSqlMapClientTemplate().queryForObject("getBstBusinessInfo",cus);
		if(cnt!=null && cnt>0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	//查询集团业务(优惠券)
	public Integer getCouponBusinessInfo(TrsModel cus)throws Exception {
		Integer cnt = (Integer)this.getSqlMapClientTemplate().queryForObject("getCouponBusinessInfo",cus);
		if(cnt!=null && cnt>0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	//查询集团业务(TRS)
	public Integer getTRSBusinessInfo(TrsModel cus)throws Exception {
		Integer cnt = (Integer)this.getSqlMapClientTemplate().queryForObject("getTRSBusinessInfo",cus);
		if(cnt!=null && cnt>0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	//获取经纬度
	public GpsInfoModel getGpsInfo(TrsModel cus)throws Exception{
		return (GpsInfoModel)this.getSqlMapClientTemplate().queryForObject("getGpsInfo", cus);
	}
	
	public static void main(String[] args) {
		ApplicationContext ctx=new FileSystemXmlApplicationContext("conf/bean.xml");
		ITrsDataDao mp=(ITrsDataDao)ctx.getBean("trsDataDao");
		Map map=new HashMap<String,Object>();
		map.put("serialid",3026938);
		map.put("partx", "part45");
		map.put("parentid",null);
		
		
	}
	/* (non-Javadoc)
	 * @see com.ideal.trsdata.dao.ITrsDataDao#getRecommend2(com.ideal.trsdata.model.ProductModel)
	 */
	public ProductModel getRecommend2(ProductModel code) throws Exception {
		return (ProductModel)this.getSqlMapClientTemplate().queryForObject("getRecommend2",code);
	}

	public List<TrsModel> getTmpProv(Map map)throws Exception{
		return this.getSqlMapClientTemplate().queryForList("getTmpProv",map);
	}

	/**
	 * 获取业务信息 2012-02-14修改
	 */
	@SuppressWarnings("unchecked")
	public List<BusiModel> getBusiInfo(TrsModel cus) throws Exception {
		return this.getSqlMapClientTemplate().queryForList("getBusiInfo",cus);
	}
	
	//查询是否有下级部门
	public String getHasDept(TrsModel cus)throws Exception {
		// 1-有下级部门 0-没有下级部门
		String hasDept = "0";
		Integer num = (Integer) this.getSqlMapClientTemplate().queryForObject("getHasDept", cus);
		if(num!=null && num>0){
			hasDept = "1";
		}
		return hasDept;
	}
	
}
